import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class dianming {
    public static void main(String[] args) throws IOException {
        int at = 0;
        int unat = 0;
        int qingjia = 0;
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
        Path file = Paths.get("src/record/" + df.format(new Date()) + ".csv");
        Files.createFile(file);
        Path writepath = Paths.get("src/record/" + df.format(new Date()) + ".csv");
        Path readpath = Paths.get("src/record/16rj.csv");
        Charset charset = Charset.forName("UTF-8");
        String line = null;
        try (BufferedReader bufferedReader = Files.newBufferedReader(readpath, charset)) {
            while ((line = bufferedReader.readLine()) != null) {
                String name = line.substring(30);
                Process pro = Runtime.getRuntime().exec("say " + name);
                System.out.println(line + "   到了吗？");
                System.out.println("[1] 正常  [2] 旷课  [3] 请假    记录：");
                Scanner scanner = new Scanner(System.in);
                int status = scanner.nextInt();
                if (status == 1) {
                    at++;
                }
                if (status == 2) {
                    unat++;
                }
                if (status == 3) {
                    qingjia++;
                }
                try (BufferedWriter bfw = Files.newBufferedWriter(writepath, charset, StandardOpenOption.APPEND)) {
                    bfw.append(line + "," + status + "\n");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            Process last = Runtime.getRuntime().exec("say 本班已到" + at + "人" + "未到" + unat + "人" + "请假" + qingjia + "人，本次点名结束");
            System.out.println("本班已到   " + at + "  人,  " + " 未到   " + unat + "   人, " + " 请假   " + qingjia + "   人，本次点名结束");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
